home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: BoundsChecker and fgets fmalloc problems
- Date: Wed, 20 Mar 96 21:26:36 GMT
- Organization: none
- Message-ID: <827357196snz@genesis.demon.co.uk>
- References: <4ikfds$h8c@nnrp1.news.primenet.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4ikfds$h8c@nnrp1.news.primenet.com>
- bri@primenet.com "Brian Gregory" writes:
-
- >I am using Bounds Checker v2.5, and am having a problem finding a
- >memory leak it is reporting...
- >
- >Example:
- >
- >fgets( szBuf, 799, fpIn );
- >
- >szBuf is an 800 character buffer (pre-sized array)
-
- In that case write:
-
- fgets( szBuf, 800, fpIn );
-
- or better still, since explicit constannts like this are a maintenance
- nightmare:
-
- fgets( szBuf, sizeof szBuf, fpIn );
-
- Or #define a buffer size.
-
- Make sure you test the return code of fgets().
-
- >fpIn IS a valid pointer
-
- I'll have to take your word for it. However a minimal working example
- which showed the problem would be proof.
-
- >no memory is corrupt before the fgets line
-
- You'll need to convince me a lot harder than that.
-
- >The application is a windows app, written in straight C with a large
- >memory model.
-
- If those are relevant to your problem you should be posting to a windows
- related newsgroup, not comp.lang.c.
-
- >The problem is Boundschecker consistently reports memory leaks for the
- >larger buffer size mallocs contained WITHIN the fgets function...
-
- It is rather unlikely that fgets() calls malloc as part of its normal
- handling. However the stdio buffering code can allocate a buffer on the first
- read or write call after a stream is opened. You can alter this behaviour
- using setbuf() or setvbuf() before the first stream read/write.
-
- >Any help on resolving this recurrent problem, or just an indication
- >that this is perhaps an erroneous error reported by Boundschecker
- >would be greatly appreciated.
-
- IMHO the most likely explanation is still a bug somewhere else in your
- program that has corrupted the heap. I don't know Boundschecker but I bet
- it can't detect all bounds violations.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-